function [su, sc, sg] = rcnl_indsh(expmval, expmu, rho, cdid)

ns         = size(expmu, 2);
eg         = (expmu .* repmat(expmval, [1 ns])).^(1 / (1 - rho));
sum1       = splitapply(@(s) sum(s, 1), eg, cdid);
denom1     = 1 ./ (sum1);              % logit share denominator (no outside good)
incValIn1  = (1 - rho) .* log(sum1);   % inclusive value of inside goods
incValAll1 = log(1 + exp(incValIn1));  % inclusive value of all goods
denom      = denom1(cdid, :);
incValIn   = incValIn1(cdid, :);
incValAll  = incValAll1(cdid, :);

A = incValIn - incValAll;
sg = exp(A);  % inside good choice probabilities
su = sg .* eg ./ exp(incValIn ./ (1 - rho)); % unconditional choice probabilities
sc = eg .* denom;                            % conditional choice probabilities
